﻿using System;
using System.Data;
using System.Web;
//引入正则表达式命名空间
using System.Text;

namespace msBsc.WebUi
{
    public partial class wfShopSearch : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindControls();
                //this.SetContrlValue("txtId", GetFormParam("ID"));
                //ShowData(GetFormParam("ID"));
                ShowData(this.Request.QueryString.Get("ID"));

                //loadGoodslist(this.Request.QueryString.Get("ID"));
            }
        }

        private void BindControls()
        {
            if (!IsPostBack)
            {
            }
        }

        public string strDealerId = "";
        public DataRow drDealer = null;
        private void ShowData(string strId)
        {
            if (string.IsNullOrEmpty(strId))
            {
                this.ToErrPage("店铺信息未找到！");
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo oCDbAccess = new msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo())
            {
                System.Data.DataSet ds = oCDbAccess.SelectById(strId);
                if (ds.Tables[0].Rows.Count <= 0)
                {
                    this.ToErrPage("店铺信息未找到！");
                    return;
                }
                else
                {
                    strDealerId = strId;
                    this.ExecJScript("$('#txtId').val('" + strDealerId + "');");

                    drDealer = ds.Tables[0].Rows[0];


                    loadHeader(strDealerId);

                    oShopSearch = new AppLogic.DataAlc.ShopSearch(HttpUtility.UrlDecode(this.Request.QueryString.ToString()), strDealerId);
                    this.ExecJScript("$('#txtQuery').val('" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(oShopSearch.GetQueryStr("", "")) + "');");
                    LoadTopForm();
                    LoadGoodsList("", "", "");
                }
            }
        }
         
        private void loadHeader(string _strDealerId)
        {
            using (msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo objtem1 = new AppLogic.DataAlc.CBizShpCommercialTenantInfo())
            {
                string strjsontem1 = objtem1.GetHeadJsonData(_strDealerId, drDealer);// msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "DATA_TYPE,DATA_TYPE_DESC,DATA_SEQ_NUM,CHILD_LINKS", 1, 1000, "DATA_SEQ_NUM ASC");
                //this.ExecJScript("debugger;");
                this.ExecJScript(@" var data= " + strjsontem1 + @" ; 
                doBoundHeader( data,'" + drDealer["HEADER_TEMPLATE_URL"].ToString() + "');");
            }
        }

        private msBsc.AppLogic.DataAlc.ShopSearch oShopSearch;
        public void LoadTopForm()
        {
            System.Text.StringBuilder sbJson = new StringBuilder();
            string strf = oShopSearch.dicQuery.ContainsKey("f") ? oShopSearch.dicQuery["f"] : "";
            sbJson.Append("{");
            sbJson.Append("\"ID\":\"" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(oShopSearch.strDealerId) + "\"");
            sbJson.Append(",\"f\":\"" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(strf) + "\"");
            sbJson.Append(",\"query\":\"" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(oShopSearch.GetQueryStr("", "")) + "\"");
            sbJson.Append(",\"nav_rows\":" + oShopSearch.GetSelectedLinkJson());
            sbJson.Append(",\"form_rows\":" + oShopSearch.GetFilterDataJson());
            sbJson.Append("}");

            //            this.ExecJScript(@"debugger;
            //");
            this.ExecJScript(@" var data= " + sbJson.ToString() + @" ; 
doBoundTopForm( data,'');");
        }
        public void LoadGoodsList(string CurrPageNum, string strPageRowsCount, string strSort)
        {
            this.ExecJScript(@" var data= " + oShopSearch.GetGoodsList(CurrPageNum, strPageRowsCount, strSort) + @" ; 
                doBoundGoodsList( data,'" + drDealer["GOODS_SEARCH_TEMPLATE_URL"].ToString() + "');");
        }

    }
}